home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15037 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  85 lines

  1. Path: pacific.st.usm.edu!not-for-mail
  2. From: mkirgan@pacific.st.usm.edu (Michael Kirgan)
  3. Newsgroups: comp.lang.c
  4. Subject: Return type - array of structures - please help!
  5. Date: 16 Apr 1996 14:53:36 GMT
  6. Organization: University of Southern Mississippi
  7. Message-ID: <4l0c9g$tsr@thorn.cc.usm.edu>
  8. NNTP-Posting-Host: ocean.st.usm.edu
  9. X-Newsreader: TIN [UNIX 1.3 950515BETA PL0]
  10.  
  11. I wish to make the function called delete to return an array of 
  12. structures or if that is not possible at least create it so when
  13. I pass an array of structures, it is by reference and not value like 
  14. listed below.
  15.  
  16. Here is an expample of my code:
  17.  
  18. typdef struct
  19.  {
  20.   char ssn[12];
  21.   char lastname[15];
  22.   char firstname[15];
  23.   char data[10];
  24.  } student;
  25.  
  26. void delete(char [], class [])
  27.  {
  28.   student temp[25]; 
  29.   /*omitted the body.  All it does is delete a struct from the array*/
  30.   /*temp is the new array with the structure deleteted and it is copied
  31.   /*back into students*/
  32.   
  33.  
  34.   class = temp;
  35.  }
  36.  
  37. main()
  38.  {
  39.   student class[25];
  40.   
  41.   /*there is now a loop to read in the class info.*/
  42.   /*next there is a loop to process options, such as printing out the
  43.     contents of the class, searching for a student in class, deleting,
  44.     & inserting*/
  45.  
  46.   /*I was currently calling delete like this:*/
  47.   delete(delssn, class);
  48.  }
  49.  
  50.  
  51. The above code works, but it passes by value, so changes are not passed back.
  52. Instead of trying to make it pass by reference I would just like functions
  53. such as delete & insert to return an array of structures.
  54.  
  55. I have called delete like this:
  56.  
  57. class = delete(delssn, class);
  58.  
  59. The above should have the same effect as when I said:  class = temp in the 
  60. function delete, except I get it returned to main, however, this seems to 
  61. give me an error.  I am assuming I get this error, because I also
  62. get an error in the following function header or prototype, depending if 
  63. I use a prototype or just list the function first:
  64.  
  65.  
  66.   student [] delete(char delssn[], char class[]);
  67.  
  68. Why does this not work?  How am I supposed to set up a return type of an
  69. array of structures?  Remember I have already done a typedef of student
  70. above, so refer to it to view the stucture.
  71.  
  72. If anyone knows please help, this is the first program I have had trouble
  73. programming for my class & I don't want to turn it in to late.  If you
  74. think it is easier to do by passing the array of structures by reference, 
  75. then please specify how I would set up function header, prototypes, how 
  76. would I call it & any other needed info.
  77.  
  78.  
  79. Thanks in advance,
  80.  
  81.  
  82.  
  83. Mike
  84. mkirgan@ocean.st.usm.edu
  85.